# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libmatroska
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.4.9
pkgrel=2
pkgdesc="Matroska library (mingw-w64)"
arch=('any')
license=('LGPL')
url="https://matroska.org"
depends=("${MINGW_PACKAGE_PREFIX}-libebml")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs')
source=("https://dl.matroska.org/downloads/${_realname}/${_realname}-${pkgver}.tar.xz"
        001-mingw-use-posix-layout.patch
        002-mingw-versioned-dll.patch
        003-export-missing-symbols.patch)
sha256sums=('38a61dd5d87c070928b5deb3922b63b2b83c09e2e4a10f9393eecb6afa9795c8'
            'bc71b9c2facf085cd6d59cf926450bc8ef1b925aaa0ca9b84cf241c66753e088'
            'fd66a3336cf7f7b914acf5dd0ba51f5e030ca45f082706093238026e97960ee6'
            '22428d36b52206c8178da408669872371b2ceba7b3109c88de27b59ea61cdb79')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-use-posix-layout.patch
  patch -p1 -i ${srcdir}/002-mingw-versioned-dll.patch
  patch -p1 -i ${srcdir}/003-export-missing-symbols.patch
}

build() {
  msg "Build shared library"
  [[ -d ${srcdir}/shared-${MINGW_CHOST} ]] && rm -rf ${srcdir}/shared-${MINGW_CHOST}
  mkdir -p ${srcdir}/shared-${MINGW_CHOST} && cd ${srcdir}/shared-${MINGW_CHOST}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-${pkgver}
  make
}

package() {
  cd "${srcdir}/shared-${MINGW_CHOST}"
  make install DESTDIR="${pkgdir}"

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.LGPL ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPL
}
